//
//  TLBrowseVideoInfo.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/10/29.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//

#import "TLBrowseVideoInfo.h"
#import "AVOSUserManger.h"
#import <AVOSCloud/AVOSCloud.h>

@implementation TLBrowseVideoInfo

/**
 *  Get Video Info By Specail video id
 *
 *  @param v_id video id the objectid Of Specail Video
 *
 *  @return TLBrowseVideoInfo instancetype
 */
+ (TLBrowseVideoInfo *)videoInfoWithVideoObj:(AVObject *)obj
{
    TLBrowseVideoInfo *videoInfo = [[TLBrowseVideoInfo alloc] initWithVideo:obj];
    
    return videoInfo;
}

- (id)initWithVideo:(AVObject *)v{
    self = [super init];
    
    if(self)
    {
        self.isload = NO;
        self.v_obj = v;
    }
    
    return self;
}

- (void)startLoadVideoInfo:(void(^)(BOOL lessDataLoaded))lessDataCompletion bigDataLoad:(void(^)(BOOL bigDataLoaded))bigDataCompletion
{
        NSString *userName = [self.v_obj objectForKey:@"pubUser"];
        NSDate *createdAt = [self.v_obj objectForKey:@"createdAt"];
        NSString *description = [self.v_obj objectForKey:@"content"];
        NSNumber *likes  = [self.v_obj objectForKey:@"likes"];
        NSString *videoURL = [self.v_obj objectForKey:@"videoUrl"];
        
            self.name = userName;
            
            self.createdAt = createdAt;
            
            self.desc = description;
            
            self.support = [NSString stringWithFormat:@"%ld",[likes integerValue]];
        
            self.videoURL = videoURL;
        

        lessDataCompletion(YES);
        self.isload = YES;

        if(userName)
        [AVOSUserManger getUserFaceByUserName:userName completion:^(UIImage *head, NSError *error) {
            if(!error)
            {
                bigDataCompletion(YES);
                self.headImg = head;
                self.isload = YES;
            }
            else
            {
                bigDataCompletion(NO);
            }
        }];
    
}

@end
